#include<iostream>
#include<string>
#include<unordered_set>
using namespace std;
string s1, s2;
int n;
unordered_set<int>S;
int get(string s, int b)
{
	int ans = 0;
	for (char x : s) {
		ans = ans * b + x - '0';
	}
	return ans;
}
int main()
{
	cin >> s1;
	cin >> s2;
	for (char& x : s1) {
		x ^= 1;	
		int val = get(s1, 2);
		S.insert(val);
		x ^= 1;
	}
	for (char& x : s2) {
		char t = x;
		for (int i = '0'; i < '3'; i++) {
			if (t == i) continue;
			x = i;
			int val = get(s2, 3);
			if (S.count(val)) {
				cout << val << endl;
				return 0;
			}
		}
		x = t;
	}
	return 0;
}